{include file="header/index" /}

<div class="container bgwhite relative">
	<p class="InforTip hides"><span id="lettertipss">0</span>封新站内信</p>
	<h2 class="mail-title">站内信</h2> {include file="common@public/alert" /}
	<p class="transceiver-box-title clearfix">
		<span class="transceiver-current" data-num="1">收件箱<span id="receivedletter"></span></span>
		<input type="hidden" value="1" id="type">
		<span data-num="0">发件箱<span id="sendletter"></span></span>
	</p>

	<div class="mt20 clearfix">
		<div class="col-xs-12">
			<form type="post">
				<select class="Batch_opera" onchange="deleteInfo(this)">
					<option>批量操作</option>
					<option>删除</option>
					<option>设置阅读</option>
				</select>
				<select class="Screen_cond">
					<option>内容</option>
				</select>
				<input class="Batch_input" type="text" value="" name="key" id="key" />
				<button class="search-btn" onclick="search()" type="button">搜索</button>
			</form>
			<button class="fr write_letters" onclick="letters()"><img class="fl" src="__IMG__/icon-bi.png">写信</button>
		</div>
	</div>
	<div class="mt20 clearfix">
		<table class="table table-bordered mb0">
			<tr>
				<th><input type="checkbox" value="on" name="all"></th>
				<th>内容</th>
				<th id="typetitle">发件人</th>
				<th>阅读时间</th>
				<th>发送时间</th>
			</tr>
			<script id="list-template" type="text/html">
				<%# for(var i=0;i<d.length;i++){  %>
				<tr>
					<td><input type="checkbox" value="<% d[i].id %>" name="rest"></td>
					<td>
						<p class="mail-txt ellipsis mt10">
							<%# if(d[i].redtype==1){ %>
							<a href="{:url('Letter/lookmail')}?id=<% d[i].id %>">
								<% d[i].content %>
							</a>
							<%# }else{ %>
							<a href="{:url('Letter/rlookmail')}?id=<% d[i].id %>">
								<% d[i].content %>
							</a>
							<%# } %>
						</p>
					</td>
					<td>
						<p class="mail-name  mt10">
							<% d[i].message_id %>
						</p>
					</td>
					<td>
						<%# if(d[i].is_status==1){ %>
						<p class="mail-time  mt10">
							<% formatDate(d[i].read_time) %>
						</p>
						<%# }else{ %>
						<p class="mail-Unread  mt10">未读</p>
						<%# } %>
					</td>
					<td>
						<p class="mail-time  mt10">
							<% formatDate(d[i].send_time)%>
						</p>
					</td>
				</tr>
				<%# } %>
			</script>
			<tbody id="list-content"></tbody>
		</table>
		<div class="Paging_bar">
			<div class=" clearfix">
				<div class="clearfix" style="float:right;margin: 0 auto;">
					<span class="fl mt5" id="count">共{$count}条数据</span><span id="allpage" class="fl  mr20 mt5"></span><span class="fl" id="AjaxPage"></span>
				</div>
				<!-- 加载动画 -->
				<div class="spiner-example">
					<div class="sk-spinner sk-spinner-three-bounce">
						<div class="sk-bounce1"></div>
						<div class="sk-bounce2"></div>
						<div class="sk-bounce3"></div>
					</div>
				</div>
			</div>
		</div>
	</div>

</div>

<div class="write_letters_center hides">
	<form name="" enctype="multipart/form-data" action="{:url('Letter/send')}" type="post">
		<div class="letter-popup">
			<h2 class="letter-popup-title">写信<span onclick="letterHides()" class="fr"><img src="__IMG__/guanbi.png"></span></h2>
			<div class="letter-choice">
				<h2>选择收件人:<img src="__IMG__/sanLine.png">
                    <span class="col-127" onclick="selectRecip(this)">总后台</span>
                    <span onclick="selectRecip(this)">运营中心</span>
                    <span onclick="selectRecip(this)">行政区域</span>
                </h2>
				<div class="mt20 mb20 letter-local">

					<!--
                    作者：2721190987@qq.com
                    时间：2017-09-11
                    描述：总后台
                     -->
					<div class="clearfix ">
						<p class="fl letters-address-left"><input class="fl totalBackgAll" type="checkbox" value="" name="" onclick="totalBackgAll(this)">全部选择</p>
						<p class="fl clearfix letters-address-right">
							{volist name="userslist.admin" id="vo"}
							<span class="fl"><input onclick="adminall(this)" type="checkbox" value="{$vo.id}" name="adminsSubset[]">{$vo.name}-{$vo.title}</span> {/volist}
						</p>
					</div>
					<!--
                        作者：2721190987@qq.com
                        时间：2017-09-11
                        描述：运营中心
                    -->
					<div class="clearfix hides">
						<p class="fl letters-address-left"><input class="fl OperaCenterAll" type="checkbox" value="" name="" onclick="totalBackgAll(this)">全部选择</p>
						<p class="fl clearfix letters-address-right">
							{volist name="userslist.operation" id="vo"}
							<span class="fl"><input onclick="adminall(this)" type="checkbox" value="{$vo.id}" name="operationSubset[]">{$vo.company_name}-{$vo.name}-{$vo.title}</span> {/volist}
						</p>
					</div>
					<!--
                        作者：2721190987@qq.com
                        时间：2017-09-11
                        描述：行政区域
                    -->
					<div class="clearfix hides">
						<p class="fl letters-address-left"><input class="fl straDivAll" type="checkbox" value="" name="" onclick="totalBackgAll(this)">全部选择</p>
						<p class="fl clearfix letters-address-right">
							{volist name="userslist.administrative" id="vo"}
							<span class="fl"><input onclick="adminall(this)" type="checkbox" value="{$vo.id}" name="adminSubset[]">{$vo.company_name}-{$vo.name}-{$vo.title}</span> {/volist}
						</p>
					</div>
				</div>
				<div class="clearfix letters-web">
					<p class="fl letters-web-left">内容</p>
					<p class="fl letters-web-right"><textarea name="content"></textarea></p>
				</div>
			</div>
			<p class="letters-btn">
				<button type="submit" class="lettersSend-btn">发送</button>
				<button type="button" class="lettersCancel-btn" onclick="letterHides()">取消</button>
			</p>
		</div>
	</form>
</div>
<!--
    作者：2721190987@qq.com
    时间：2017-08-31
    描述：信息提示
-->

<script>
	$(".transceiver-box-title>span").click(function() {
		$(this).addClass("transceiver-current");
		$(this).siblings().removeClass("transceiver-current");
		var num = $(this).data("num");
		$("#type").val(num);
		$("#key").val('');
		Ajaxpage();
	})

	//各个权限显示
	function selectRecip(obj) {
		$(obj).addClass("col-127").siblings().removeClass("col-127");
		var num = $(obj).index() - 1;
		$(".letter-local>div").eq(num).show().siblings().hide()
	}

	$("input[name='all']").click(function() {
		if($(this).is(":checked")) {
			$("input[name='rest']").prop("checked", true)
		} else {
			$("input[name='rest']").prop("checked", false)
		}
	})

	function letters() {
		$(".write_letters_center").show();
	}

	function letterHides() {
		$(".write_letters_center").hide();
	}

	function admins(obj) {
		if($(obj).is(":checked")) {
			$(obj).parents(".operation-center").find(".operation-center-right").find("input").prop("checked", true)
		} else {
			$(obj).parents(".operation-center").find(".operation-center-right").find("input").prop("checked", false)
		}
	}

	function operation(obj) {
		if($(obj).is(":checked")) {
			$(obj).parents(".operation-center").find(".operation-center-right").find("input").prop("checked", true)
		} else {
			$(obj).parents(".operation-center").find(".operation-center-right").find("input").prop("checked", false)
		}
	}

	function administration(obj) {
		if($(obj).is(":checked")) {
			$(obj).parents(".administration-center").find(".administration-center-right").find("input").prop("checked", true)
		} else {
			$(obj).parents(".administration-center").find(".administration-center-right").find("input").prop("checked", false)
		}
	}

	//总后台选择
	function totalBackgAll(obj) {
		if($(obj).is(":checked")) {
			$(obj).parent().next().find("input").prop("checked", true)
		} else {
			$(obj).parent().next().find("input").prop("checked", false)
		}
	}

	function adminall(obj) {
		var inputNum = $(obj).parents("p").find("input").length;
		var all = 0;
		for(var i = 0; i < inputNum; i++) {
			if($(obj).parents("p").find("input").eq(i).is(":checked")) {
				all++
			}
		}
		if(all == inputNum) {
			$(obj).parents("p").prev("p").find("input").prop("checked", true)
		} else {
			$(obj).parents("p").prev("p").find("input").prop("checked", false)
		}
	}

	function deleteInfo(obj) {
		var type = $("#type").val();
		var str = [];
		$.each($('input:checkbox:checked'), function() {
			str.push($(this).val());
		});
		var rest = $("input[name='rest']")
		if($(obj).val() == "删除") {
			if(rest.is(":checked")) {
				layer.alert('确认删除选中的所有信息吗?', {
					btn: ['确认', '取消'], //按钮
				}, function() {
					$.post("{:url('Letter/dels')}", {
						ids: str,
						redtype: type
					}, function(data) {
						layer.msg(data.msg, {
							time: 1000,
						});
						Ajaxpage();
						restCheck();
					})
				});
			} else {
				layer.msg('你还没有选中的信息', {
					time: 1000
				})
			}
		}
		if($(obj).val() == "设置阅读") {
			if(rest.is(":checked")) {
				layer.alert('确认阅读选中的所有信息吗?', {
					btn: ['确认', '取消'], //按钮
				}, function() {
					$.post("{:url('Letter/reds')}", {
						ids: str,
						redtype: type
					}, function(data) {
						layer.msg(data.msg, {
							time: 1000,
						});
						Ajaxpage();
						restCheck();
					})
				});
			} else {
				layer.msg('你还没有选中的信息', {
					time: 1000
				})
			}
		}
	}

	//遍历所有选中的复选框
	function restCheck() {
		$("input[name='rest']").each(function() {
			if($(this).is(':checked')) {
				$(this).parents("tr").remove()
			}
		});
		$("input[name='all']").prop("checked", false);
	}

	function search() {
		Ajaxpage();
	}

	//laypage分页
	Ajaxpage();

	function Ajaxpage(curr) {
		var type = $("#type").val();
		var key = $('#key').val();
		$.getJSON('{:url("Letter/index")}', {
			page: curr || 1,
			type: type,
			key: key
		}, function(data) {
			$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
			$('#count').html("共" + data.count + "条数据");
			$('#receivedletter').html("(" + data.rcount + "/" + data.zrcount + ")");
			$('#sendletter').html("(" + data.zscount + ")");
			$('#lettertips').html(data.rcount);
			if(type == 1) {
				$('#typetitle').html('发件人');
			} else {
				$('#typetitle').html('收件人');
			}
			if(data == '') {
				$("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
			} else {
				var tpl = document.getElementById('list-template').innerHTML;
				laytpl.config({
					open: '<%',
					close: '%>'
				});
				laytpl(tpl).render(data.data, function(html) {
					document.getElementById('list-content').innerHTML = html;
				});
				laypage({
					cont: $('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
					pages: data.allpage, //总页数
					skip: true, //是否开启跳页
					skin: '#337ab7', //分页组件颜色
					curr: curr || 1,
					first: '首页', //若不显示，设置false即可
					last: '尾页', //若不显示，设置false即可
					groups: 3, //连续显示分页数
					jump: function(obj, first) {
						if(!first) {
							Ajaxpage(obj.curr)
						}
						$('#allpage').html('，第' + obj.curr + '页，共' + '<i>' + obj.pages + '</i>' + '页');
						inputlength();
					}
				});
			}
		});
	}

	function formatDate(now) {
		var d = new Date(now * 1000);
		var year = d.getFullYear(),
			month = d.getMonth() + 1,
			date = d.getDate(),
			hour = d.getHours(),
			minute = d.getMinutes(),
			second = d.getSeconds();
		return year + "年" + month + "月" + date + "日 " + hour + ":" + minute + ":" + second;
	}

	message_z_tips();

	function message_z_tips() {
		$.get("{:url('Letter/tips')}", function(data) {
			$('#lettertipss').html(data.rcount);
			if(data.rcount > 0) {
				$('.InforTip').show();
			} else {
				$('.InforTip').hide();
			}

		}, 'json');
		setTimeout('message_z_tips()', 5000);
	}
</script>
</body>

</html>